package com.zhou.demo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.BitmapRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.zhou.demo.model.DateDetail;
import com.zhou.demo.model.Footer;
import com.zhou.demo.model.MyDate;
import com.zhou.demo.zhihn.R;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created by 11065 on 2016/8/19.
 */
public class DateDetailRecycleViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Object> list = new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;
    public BitmapRequestBuilder<GlideUrl, Bitmap> requestBuilder;
    private int TYPE_LIST = 0;
    private int TYPE_FOOTER = 1;


    public DateDetailRecycleViewAdapter(Context context, List<Object> list) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        requestBuilder = Glide.with(context)
                .from(GlideUrl.class)
                .asBitmap()
                .dontAnimate()
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 0) {
            View view = inflater.inflate(R.layout.date_detail, parent, false);
            MyViewHolder viewHolder = new MyViewHolder(view);
            return viewHolder;
        } else if (viewType == 1) {
            View view = inflater.inflate(R.layout.recycler_footer, parent, false);
            FooterViewHolder footerViewHolder = new FooterViewHolder(view);
            return footerViewHolder;
        }

        return null;
    }

    @Override
    public int getItemViewType(int position) {
        if (list.get(position) instanceof MyDate) {
            return TYPE_LIST;
        } else if (list.get(position) instanceof Footer)
            return TYPE_FOOTER;

        return -1;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      /*  requestBuilder.load(new GlideUrl(list.get(position).getImages().get(0))).into(holder.imageView);
        holder.textView_title.setText(list.get(position).getTitle());*/

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView textView_title;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            textView_title = (TextView) itemView.findViewById(R.id.textView_title);
        }
    }

    public class FooterViewHolder extends RecyclerView.ViewHolder {


        public FooterViewHolder(View itemView) {
            super(itemView);
        }

    }

}
